package com.yjc.springcloud.controller;

import com.yjc.springcloud.bean.CommotResult;
import com.yjc.springcloud.bean.Payment;
import com.yjc.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;


/**
 * @author shkstart
 * @create 2022-07-12 20:39
 */
@RestController
public class PaymentController {

    @Autowired
    PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/add/payment")
    public CommotResult addPayment(@RequestBody Payment payment) {
        int res = paymentService.addPayMent(payment);
        return res > 0 ? new CommotResult(200, "插入订单成功" + serverPort, res) :
                new CommotResult(444, "插入订单失败", null);
    }

    @GetMapping("/get/payment/{id}")
    public CommotResult<Payment> addPayment(@PathVariable("id") Long id) {
        Payment res = paymentService.getPaymentById(id);
        System.out.println(111);
        return res != null ? new CommotResult<Payment>(200, "成功查询到订单" + serverPort, res) :
                new CommotResult<Payment>(444, "未查询到该id订单", null);
    }

    @GetMapping("/payment/lb")
    public String lb() {
        return serverPort;
    }

}
